using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Windows.Forms;
class PrintableForm: Form
{

	public PrintableForm()
	{
		Text = "Printable Form";
		BackColor = SystemColors.Window;
		ForeColor = SystemColors.WindowText;
		ResizeRedraw = true;
	}
	protected override void OnPaint(PaintEventArgs pea)
	{
		DoPage(pea.Graphics, ForeColor,
			ClientSize.Width, ClientSize.Height);
	}
	protected override void OnClick(EventArgs ea)
	{
		PrintDocument prndoc = new PrintDocument();
		prndoc.DocumentName = Text;
		prndoc.PrintPage +=
			new PrintPageEventHandler(PrintDocumentOnPrintPage);
		prndoc.Print();
	}
	void PrintDocumentOnPrintPage(object obj, PrintPageEventArgs ppea)
	{
		Graphics grfx = ppea.Graphics;
		SizeF sizef = grfx.VisibleClipBounds.Size;
		DoPage(grfx, Color.Black, (int)sizef.Width, (int)sizef.Height);
	}
	protected virtual void DoPage(Graphics grfx, Color clr, int cx, int
		cy)
	{
		Pen pen = new Pen(clr);
		grfx.DrawLine(pen, 0, 0, cx - 1, cy - 1);
		grfx.DrawLine(pen, cx - 1, 0, 0, cy - 1);
	}
}

class WhatSize: PrintableForm
{
	public  static void Main()
	{
		Application.Run(new WhatSize());
	}
	public WhatSize()
	{
		Text = "What Size?";
	}
	protected override void DoPage(Graphics grfx, Color clr, int cx, int
		cy)
	{
		
//		grfx.DrawRectangle(Pens.Red ,0,0,grfx.VisibleClipBounds.Width,
//			grfx.VisibleClipBounds.Height);
//		grfx.DrawString(grfx.VisibleClipBounds.ToString()+grfx.PageScale.ToString()+grfx.PageUnit.ToString(),Font,Brushes.Red,0,0);

		Brush brush = new SolidBrush(clr);
		int y = 0;
		DoIt(grfx, brush, ref y, GraphicsUnit.Pixel);
		DoIt(grfx, brush, ref y, GraphicsUnit.Display);
		DoIt(grfx, brush, ref y, GraphicsUnit.Document);
		DoIt(grfx, brush, ref y, GraphicsUnit.Inch);
		DoIt(grfx, brush, ref y, GraphicsUnit.Millimeter);
		DoIt(grfx, brush, ref y, GraphicsUnit.Point);
	}
	void DoIt(Graphics grfx, Brush brush, ref int y, GraphicsUnit gu)
	{
		GraphicsState gs = grfx.Save();
		grfx.PageUnit = gu;
		grfx.PageScale = 1;
		SizeF sizef = grfx.VisibleClipBounds.Size;
		grfx.Restore(gs);
		grfx.DrawString(gu+ ": " + sizef, Font, brush, 0, y);
		y += (int) Math.Ceiling(Font.GetHeight(grfx));
	}
}